#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSystemTrayIcon>
#include <QActionGroup>
#include <QSignalMapper>

#include "MDeviceManager.h"

using namespace Mikroakustika::MDeviceChecker;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow {
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void help();
    void about();
    void menuSelect();
    void saveCOMPortSetting(const QString &comPortName);
    void iconActivated(QSystemTrayIcon::ActivationReason reason);
    void on_chkbxAutorun_stateChanged(int arg1);
    void on_chkbxAutoCheckNewDevice_stateChanged(int arg1);

    quint16 getComPortNumber(const QString &comPort);

protected:
    void changeEvent(QEvent *e);
    void closeEvent(QCloseEvent *event);

private:
    void createMainActions();
    void createTrayIcon();
    void addNewActions();
    void createMenuActions();
    void checkMenuItemAtFirstStart();

    bool readCurrentSerialPort();
    bool selectLastCheckMenu();

    QString readMaDecoderPortSetting();
    QString getCOMPortNameSetting();

    Ui::MainWindow *ui;

    MDeviceManager *mDevManager;

    QAction *minimizeAction;
    QAction *restoreAction;
    QAction *aboutAction;
    QAction *menuHelp;
    QAction *quitAction;

    QAction *tmpMenuItem;
    QVector<QAction*> vectorOfAction;

    QActionGroup *menuGroupTmpActions;
    QActionGroup *menuGroupMainAction;

    QSystemTrayIcon *trayIcon;
    QMenu *trayIconMenu;

    QString textLastCheckedMenuItem;
    QString textCurrentCheckedMenuItem;
    QStringList checkableList;

    QString comPortNameF3Setting;
    bool firstStartApp;

public slots:
    void reconstructTrayMenu(connDevicesType &devList,
                             avSerPort &portList,
                             QString &captionOfSerialPort,
                             devStatus statusConn,
                             bool isNeedManufacturer);

    void showMessageTrayBaloon(QString &txt);

};

#endif // MAINWINDOW_H
